package hello.controller;

import hello.util.JwtUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 针对 JWT 实现的 登录管理
 * @Author: m01
 * @Date: created at  2018/12/20  15:15
 * @Modified By:
 */

@RequestMapping(value = "/login")
@Controller
public class ApiLoginController {


    @RequestMapping(value = "/api", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, String> login(@RequestParam(value = "username", required = true, defaultValue = "") String username,
                                     @RequestParam(value = "password", required = true, defaultValue = "") String password) {

        //确认 用户
        String jwttoken = "";
        if(true){
            Map<String, String> map = new HashMap<>();
            map.put("username",username);
            map.put("password",password);
            jwttoken = JwtUtils.getToken(map, 1000 * 60 * 5l);
        }
        Map<String, String> map = new HashMap<>();
        map.put("code", "200");
        map.put("jwttoken", jwttoken);

        System.out.println(jwttoken);
        return map;


    }

    @RequestMapping(value = "/test")
    @ResponseBody
    public String test(){
        return "NMB";
    }
}
